/**
 * @param {string} s
 * @return {number}
 */
var firstUniqChar = function (s) {
  let map = new Map();
  let set = new Set();
  for (let i = 0; i < s.length; i++) {
    if (set.has(s[i])) {
      continue;
    }
    if (map.has(s[i])) {
      map.delete(s[i]);
      set.add(s[i]);
      continue;
    }
    map.set(s[i], i);
  }
  let min = -1;
  map.forEach((i) => {
    if (i < min || min === -1) {
      min = i;
    }
  });
  return min;
};
